{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Coding Exercise: Get Headers and Paragraphs\n",
    "\n",
    "In the cell below, use what you learned in the previous lessons to print only the text from all the `<h2>` and `<p>` tags inside the `<div>` tags that have a `class=\"section\"` attribute. For this quiz use the `sampe.html` file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Student Hub\n",
      "Student Hub is our real time collaboration platform where you can work with peers and mentors. You will find Community rooms with other students and alumni.\n",
      "\n",
      "Knowledge\n",
      "Search or ask questions in Knowledge\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Import BeautifulSoup\n",
    "from bs4 import BeautifulSoup\n",
    "\n",
    "# Open the HTML file and create a BeautifulSoup Object\n",
    "with open('./sample.html') as f:\n",
    "    page_content = BeautifulSoup(f, 'lxml')\n",
    "\n",
    "# Print only the text from all the <h2> and <p> tags inside the <div> tags that have a class=\"section\" attribute\n",
    "for section in page_content.find_all('div', class_='section'):\n",
    "    header = section.h2.get_text()\n",
    "    print(header)\n",
    "    paragraph = section.p.get_text()\n",
    "    print(paragraph)\n",
    "    print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
